#include <stdio.h>
#include <stdlib.h>

//https://leetcode.cn/problems/remove-linked-list-elements/description/

struct ListNode {
    int val;
    struct ListNode *next;
};

struct ListNode *removeElements(struct ListNode *head, int val) {
    struct ListNode *prev = NULL;
    struct ListNode *cur = head;
    while (cur != NULL) {
        if (head->val == val) {
            head = head->next;
            free(cur);
            cur = head;
        } else if (cur->val == val) {
            prev->next = cur->next;
            free(cur);
            cur = prev->next;
        } else {
            prev = cur;
            cur = cur->next;
        }
    }
    return head;
}

int main() {

    return 0;
}